package com.dstz.bpm.engine.action.cmd;

import com.dstz.bpm.api.engine.action.cmd.BaseActionCmd;
import com.dstz.bpm.api.engine.action.cmd.FlowRequestParam;
import com.dstz.bpm.api.engine.action.cmd.InstanceActionCmd;
import com.dstz.bpm.api.exception.BpmStatusCode;
import com.dstz.bpm.api.exception.WorkFlowException;
import java.util.Map;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;

public class DefaultInstanceActionCmd extends BaseActionCmd implements InstanceActionCmd {
   protected ExecutionEntity ay;

   public DefaultInstanceActionCmd(FlowRequestParam flowParam) {
      super(flowParam);
   }

   public DefaultInstanceActionCmd() {
   }

   public String getFlowKey() {
      return this.getBpmDefinition().getKey();
   }

   @Override
   public String getSubject() {
      return this.getBpmInstance().getSubject();
   }

   public ExecutionEntity getExecutionEntity() {
      return this.ay;
   }

   public void setExecutionEntity(ExecutionEntity executionEntity) {
      this.ay = executionEntity;
   }

   @Override
   public Object getVariable(String variableName) {
      if (this.ay == null) {
         throw new WorkFlowException(BpmStatusCode.VARIABLES_NO_SYNC);
      } else {
         return this.ay.getVariable(variableName);
      }
   }

   @Override
   public boolean hasVariable(String variableName) {
      if (this.ay == null) {
         throw new WorkFlowException(BpmStatusCode.VARIABLES_NO_SYNC);
      } else {
         return this.ay.hasVariable(variableName);
      }
   }

   @Override
   public void removeVariable(String variableName) {
      if (this.ay == null) {
         throw new WorkFlowException(BpmStatusCode.VARIABLES_NO_SYNC);
      } else {
         this.ay.removeVariable(variableName);
      }
   }

   @Override
   public void addVariable(String name, Object value) {
      if (this.ay == null) {
         throw new WorkFlowException(BpmStatusCode.VARIABLES_NO_SYNC);
      } else {
         this.ay.setVariable(name, value);
      }
   }

   @Override
   public Map<String, Object> getVariables() {
      return this.ay.getVariables();
   }

   @Override
   public void initSpecialParam(FlowRequestParam flowParam) {
   }

   @Override
   public String getNodeId() {
      return this.ay == null ? null : this.ay.getActivityId();
   }
}
